package top.kaoshanji.p1ch04a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.MessageFormat;

/**
 * 代码清单 p1ch04a-15：MessageFormat类的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/16 17:12
 */
public class MessageFormatExample01 {

    private static final Logger logger = LogManager.getLogger(MessageFormatExample01.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch04a-15：MessageFormat类的使用示例...");

        String pattern = "购买了{0,number,integer}件商品，单价为{1,number,currency}，合计：{2,number,\u00A4#,###.##}";
        MessageFormat format = new MessageFormat(pattern);
        int count = 3;
        double price = 1599.3;
        double total = price * count;
        String patternStr = format.format(new Object[]{count, price, total});
        logger.info("...patternStr:{}...", patternStr);

    }


}
